using System;
using System.Collections.Generic;
using System.Text;
using AF_ORM.CORE;
using Bussiness.Entity;
using System.Data;
using System.Data.SqlClient;
using log4net;
namespace Bussiness.Manager
{


    public class PT_ServiceBillManager : Bussiness.ManagerBase.PT_ServiceBillManagerBase
    {
        private static readonly ILog _logger = LogManager.GetLogger(typeof(PT_ServiceBillManager).Name);
        public static PT_ServiceBillManager CreateInstant()
        {

            return new PT_ServiceBillManager();
        }
        /*
        public string GetID()
        {
            string id = "";
            PT_SEQNOEntity obj = new PT_SEQNOEntity();
            obj.TableSeq = "PT_ServiceBill";
            obj.ColumnSeq = "Bill_NO";

            List<PT_SEQNOEntity>lst = PT_SEQNOManager.CreateInstant().SelectWithConditionLST(obj);
            if (lst.Count > 0)
            {
                obj = lst[0];
                id = obj.Prefix;
                int leng = obj.Lenght - obj.Prefix.Length;
                int current = obj.LastNumber;
                int max = (int)Math.Pow(10,leng);
                while (current < max)
                {
                    id += "0";
                    max = max * 10;
                }
                id += (obj.LastNumber + 1);
                obj.LastNumber = obj.LastNumber + 1;
                PT_SEQNOManager.CreateInstant().Update(obj);
            }
            return id;  
          


        }
         * */

        public PT_ServiceBillEntity GetByBillNo(string billNo)
        {
            try
            {
                PT_ServiceBillEntity objCond = new PT_ServiceBillEntity();
                objCond.Bill_NO = billNo;
                objCond.IsDeleted = false;

                List<PT_ServiceBillEntity> lst = PT_ServiceBillManager.CreateInstant().SelectWithConditionLST(objCond);
                if (lst.Count > 0)
                    return lst[0];

                return null;
            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message);
                return null;
            }
        }

        public PT_ServiceBillEntity GetByQOT_NO(string QOT_NO)
        {
            try
            {
                PT_ServiceBillEntity objCond = new PT_ServiceBillEntity();
                objCond.QOT_NO = QOT_NO;
                objCond.IsDeleted = false;

                List<PT_ServiceBillEntity> lst = PT_ServiceBillManager.CreateInstant().SelectWithConditionLST(objCond);
                if (lst.Count > 0)
                    return lst[0];
                return null;
            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message);
                return null;
            }
        }

        public DataTable GetDealerByUserId(int userId)
        {
            try
            {
                string sql = @"
                       select DMS002.Short_Name,DMS002.DEALER_CODE,DMS002.HEAD_ADD,DMS002.HEAD_TEL,DMS002.HEAD_FAX
                        from PT_Account ACC
                            INNER JOIN DMS002 ON (ACC.DEALER_CODE = DMS002.DEALER_CODE)
                        where ACC.UserId = @UserID
                    ";
                SqlParameter[] param = new SqlParameter[1];
                param[0] = new SqlParameter("@UserId", userId);
                return SqlHelper.ExecuteDataTable(Config.ConnectionConfig.ConnectionString, CommandType.Text, sql, param);
            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message);
                return new DataTable();
            }
        }

        public DataTable Search(string condition
            , string recievedBy
            , string repairedBy
            , string from, string to
            , bool searchName, bool searchPhone
            , bool searchNumber
            , bool searchSKSM
            , bool searchBillNo
            )
        {
            try
            {
                string sql = @"select Bill_NO                           
                            ,CustName
                            ,Phone
                            ,ModelName
                             ,RC.UserName as RecievedBy
                             ,convert(varchar(19),InputDate,121) as InputDate
                            ,RP.UserName as RepairedBy
                            , convert(varchar(19),RepairDate ,121) as RepairDate
                             ,convert(varchar(19),OutputDate,121) as OutputDate
                            ,RepairPaid
                            ,ToolPaid
                        from PT_ServiceBill B LEFT JOIN DMS081 ON DMS081.UserName = B.AgentCode 
                                            INNER JOIN PT_HondaModel M ON B.Model = M.ModelCode
                             LEFT JOIN PT_Account RP ON B.RepairedBy = RP.UserCode
                             LEFT JOIN PT_Account RC ON B.RepairedBy = RC.UserCode
                        where b.isdeleted = 0 and(1<>1  ";
                if (searchName)
                    sql += " or CustName  like N'%" + condition + "%' ";
                if (searchNumber)
                    sql += " or NumberPlate   like '%" + condition + "%' ";
                if (searchPhone)
                    sql += " or Phone  like '%" + condition + "%' ";
                if (searchSKSM)
                    sql += " or MachineCode  like '%" + condition + "%'";
                if (searchBillNo)
                    sql += " or Bill_NO  like '%" + condition + "%' ";
                sql += ")";
                if (!string.IsNullOrEmpty(from))
                    sql += " and DateDiff(day,'" + from + "',InputDate) >=0 ";
                if (!string.IsNullOrEmpty(to))
                    sql += " and DateDiff(day,'" + to + "',InputDate) <=0 ";
                if (!string.IsNullOrEmpty(recievedBy))
                    sql += " and recievedBy = '" + recievedBy + "' ";
                if (!string.IsNullOrEmpty(repairedBy))
                    sql += " and repairedBy = '" + repairedBy + "' ";

                return SqlHelper.ExecuteDataTable(Config.ConnectionConfig.ConnectionString, CommandType.Text, sql);
            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message);
                return new DataTable();
            }
        }

        public DataTable SummaryByAgent(bool showExistedAgentOnly, DateTime from, DateTime to)
        {
            try
            {
                string sql = "sp_PT_AgentSummary";
                SqlParameter[] param = new SqlParameter[3];
                param[0] = new SqlParameter("@from", from);
                param[1] = new SqlParameter("@to", to);
                param[2] = new SqlParameter("@showType", showExistedAgentOnly ? "1" : "0");

                return SqlHelper.ExecuteDataTable(Config.ConnectionConfig.ConnectionString, CommandType.StoredProcedure, sql, param);
            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message);
                return new DataTable();
            }
        }
        public bool CheckBillExistedInDMS(string bill_No, string serviceType)
        {
            try
            {
                bool isExisted = false;
                switch (serviceType)
                {
                    case "BH":
                    case "RB":
                        DataTable tbl1 = DMS052Manager.CreateInstant().SelectByRMRK1(bill_No);
                        isExisted = tbl1.Rows.Count > 0;
                        break;
                    case "SC":
                        DataTable tbl = DMS027Manager.CreateInstant().SelectByRPO_NO(bill_No);
                        isExisted = tbl.Rows.Count > 0;
                        break;
                }
                return isExisted;
            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message);
                return false;
            }
        }

        public DataTable GetToolListOfBill(string bill_No, bool isForNew)
        {
            try
            {
                DataTable tbl = new DataTable();
                SqlParameter[] param = new SqlParameter[2];
                param[0] = new SqlParameter("@BillNo", bill_No);
                param[1] = new SqlParameter("@forInsert", isForNew ? "1" : "0");
                return SqlHelper.ExecuteDataTable(Config.ConnectionConfig.ConnectionString, CommandType.StoredProcedure, "sp_PT_GetToolInBill", param);
            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message);
                return new DataTable();
            }
        }

        public DataTable GetToolListOfBill(string bill_No, int ToolType)
        {
            try
            {
                string sql = @"SELECT *
                           FROM PT_ToolInBill
                           WHERE BillNo = @BillNo AND ToolType = @ToolType";
                SqlParameter[] param = new SqlParameter[2];
                param[0] = new SqlParameter("@BillNo", bill_No);
                param[1] = new SqlParameter("@ToolType", ToolType);

                return SqlHelper.ExecuteDataTable(Config.ConnectionConfig.ConnectionString, CommandType.Text, sql, param);
            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message);
                return new DataTable();
            }
        }
        public DataTable Report(DateTime fromDate, DateTime toDate)
        {
            try
            {
                SqlParameter[] param = new SqlParameter[2];
                param[0] = new SqlParameter("@FromDate", fromDate);
                param[1] = new SqlParameter("@ToDate", toDate);
                return SqlHelper.ExecuteDataTable(Config.ConnectionConfig.ConnectionString, CommandType.StoredProcedure, "Report", param);
            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message);
                return new DataTable();
            }
        }
        public DataTable ReportPart2(DateTime fromDate, DateTime toDate)
        {
            try
            {
                SqlParameter[] param = new SqlParameter[2];
                param[0] = new SqlParameter("@FromDate", fromDate);
                param[1] = new SqlParameter("@ToDate", toDate);
                return SqlHelper.ExecuteDataTable(Config.ConnectionConfig.ConnectionString, CommandType.StoredProcedure, "ReportPart2", param);
            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message);
                return new DataTable();
            }
        }
        public DataTable ReportByBillNo(DateTime fromDate, DateTime toDate)
        {
            try
            {
                SqlParameter[] param = new SqlParameter[2];
                param[0] = new SqlParameter("@FromDate", fromDate);
                param[1] = new SqlParameter("@ToDate", toDate);
                return SqlHelper.ExecuteDataTable(Config.ConnectionConfig.ConnectionString, CommandType.StoredProcedure, "ReportByBillNo", param);
            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message);
                return new DataTable();
            }
        }
        public DataTable Reportturnover(DateTime fromDate, DateTime toDate)
        {
            try
            {
                SqlParameter[] param = new SqlParameter[2];
                param[0] = new SqlParameter("@from", fromDate);
                param[1] = new SqlParameter("@to", toDate);
                return SqlHelper.ExecuteDataTable(Config.ConnectionConfig.ConnectionString, CommandType.StoredProcedure, "Report_DoanhThu_DichVu_PhuTung_Nhot", param);
            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message);
                return new DataTable();
            }
        }
        public DataTable ReportByAgent(DateTime fromDate, DateTime toDate)
        {
            try
            {
                SqlParameter[] param = new SqlParameter[3];
                param[0] = new SqlParameter("@showType", '1');
                param[1] = new SqlParameter("@from", fromDate);
                param[2] = new SqlParameter("@to", toDate);
                return SqlHelper.ExecuteDataTable(Config.ConnectionConfig.ConnectionString, CommandType.StoredProcedure, "sp_PT_AgentSummary", param);
            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message);
                return new DataTable();
            }
        }
        public DataTable ReportDoanhSoDVHangKy(DateTime fromDate, DateTime toDate)
        {
            try
            {
                SqlParameter[] param = new SqlParameter[2];
                param[0] = new SqlParameter("@from", fromDate);
                param[1] = new SqlParameter("@to", toDate);
                return SqlHelper.ExecuteDataTable(Config.ConnectionConfig.ConnectionString, CommandType.StoredProcedure, "sp_PT_BC3_DoanhSoDichVuHangKy", param);

            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message);
                return new DataTable();
            }
        }
        public DataTable ReportDoanhSoDVHangKyChiTiet(DateTime fromDate, DateTime toDate)
        {
            try
            {
                SqlParameter[] param = new SqlParameter[2];
                param[0] = new SqlParameter("@from", fromDate);
                param[1] = new SqlParameter("@to", toDate);
                return SqlHelper.ExecuteDataTable(Config.ConnectionConfig.ConnectionString, CommandType.StoredProcedure, "sp_PT_BC2_DoanhSoDichVuHangKyChiTiet", param);
            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message);
                return new DataTable();
            }
        }
        public DataTable SearchBill(string ServiceType, string tukhoa, DateTime fromDate, DateTime toDate, int nvSuaChua, int nvTiepNhan, int nvKiemTra, int nvThuNgan, bool isTatca, bool isHoTen, bool isBienSo, bool isSKSM, bool isSoDienThoai, bool isSoPhieu)
        {
            try
            {
                SqlParameter[] param = new SqlParameter[14];
                param[0] = new SqlParameter("@serviceType", ServiceType);
                param[1] = new SqlParameter("@tukhoa", tukhoa);
                param[2] = new SqlParameter("@fromdate", fromDate);
                param[3] = new SqlParameter("@toDate", toDate);
                param[4] = new SqlParameter("@suachua", nvSuaChua);
                param[5] = new SqlParameter("@tiepnhan", nvTiepNhan);
                param[6] = new SqlParameter("@kiemtra", nvKiemTra);
                param[7] = new SqlParameter("@thungan", nvThuNgan);
                param[8] = new SqlParameter("@isTatca", isTatca);
                param[9] = new SqlParameter("@isHoten", isHoTen);
                param[10] = new SqlParameter("@isBienso", isBienSo);
                param[11] = new SqlParameter("@isSKSM", isSKSM);
                param[12] = new SqlParameter("@isSodienthoai", isSoDienThoai);
                param[13] = new SqlParameter("@isSoPhieu", isSoPhieu);
                return SqlHelper.ExecuteDataTable(Config.ConnectionConfig.ConnectionString, CommandType.StoredProcedure, "SearchBill", param);
            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message);
                return new DataTable();
            }
        }

        public string GetNewServiceCode()
        {
            try
            {
                SqlParameter[] param = new SqlParameter[2];
                param[0] = new SqlParameter("@tableName", "PT_ServiceBill");
                param[1] = new SqlParameter("@code", "");
                param[1].Direction = ParameterDirection.Output;
                param[1].DbType = DbType.String;
                param[1].Size = 10;
                SqlHelper.ExecuteNonQuery(Config.ConnectionConfig.ConnectionString, CommandType.StoredProcedure, "sp_PTGetLastSEQ", param);
                return param[1].Value.ToString();
            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message);
                return "";
            }
        }
        public DataSet GetReportTop(string BillNo)
        {
            try
            {
                SqlParameter[] param = new SqlParameter[1];
                param[0] = new SqlParameter("@BillNo", BillNo);
                return SqlHelper.ExecuteDataSet(Config.ConnectionConfig.ConnectionString, CommandType.StoredProcedure, "GetReportTop", param);
            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message);
                return new DataSet();
            }
        }
        public DataSet GetReportMiddle(string BillNo)
        {
            try
            {
                SqlParameter[] param = new SqlParameter[1];
                param[0] = new SqlParameter("@BillNo", BillNo);
                return SqlHelper.ExecuteDataSet(Config.ConnectionConfig.ConnectionString, CommandType.StoredProcedure, "GetReportMiddle", param);
            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message);
                return new DataSet();
            }
        }
        public DataSet GetReportBottom(string BillNo)
        {
            try
            {
                SqlParameter[] param = new SqlParameter[1];
                param[0] = new SqlParameter("@BillNo", BillNo);
                return SqlHelper.ExecuteDataSet(Config.ConnectionConfig.ConnectionString, CommandType.StoredProcedure, "GetReportBottom", param);
            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message);
                return new DataSet();
            }

        }
        public DataSet GetReportTotal(string BillNo)
        {
            try
            {
                SqlParameter[] param = new SqlParameter[1];
                param[0] = new SqlParameter("@BillNo", BillNo);
                return SqlHelper.ExecuteDataSet(Config.ConnectionConfig.ConnectionString, CommandType.StoredProcedure, "ReportTotalTocharacter", param);
            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message);
                return new DataSet();
            }
        }
        public DataSet GetReportHead(int UserId)
        {
            try
            {
                SqlParameter[] param = new SqlParameter[1];
                param[0] = new SqlParameter("@UserId", UserId);
                return SqlHelper.ExecuteDataSet(Config.ConnectionConfig.ConnectionString, CommandType.StoredProcedure, "GetReportHead", param);
            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message);
                return new DataSet();
            }
        }
        public DataTable ReportDoanhThuDichVuPhuTungNhot(DateTime fromDate, DateTime toDate)
        {
            try
            {
                SqlParameter[] param = new SqlParameter[2];
                param[0] = new SqlParameter("@from", fromDate);
                param[1] = new SqlParameter("@to", toDate);
                return SqlHelper.ExecuteDataTable(Config.ConnectionConfig.ConnectionString, CommandType.StoredProcedure, "sp_PT_BC6_BaoCaoDoanhThuDV_PT_Nhot_HVN", param);
            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message);
                return new DataTable();
            }
        }
        public DataTable ReportSoLuongXeDenKhuVucDichVuTrongNgay(DateTime fromDate, DateTime toDate)
        {
            try
            {
                SqlParameter[] param = new SqlParameter[2];
                param[0] = new SqlParameter("@from", fromDate);
                param[1] = new SqlParameter("@to", toDate);
                return SqlHelper.ExecuteDataTable(Config.ConnectionConfig.ConnectionString, CommandType.StoredProcedure, "sp_PT_BC7_SoLuongXeDenKhuVucDichVuTheoMuiGio", param);
            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message);
                return new DataTable();
            }
        }
        public DataTable ReportTongHopLanDenCuaKhachHang(DateTime fromDate, DateTime toDate)
        {
            try
            {
                SqlParameter[] param = new SqlParameter[2];
                param[0] = new SqlParameter("@from", fromDate);
                param[1] = new SqlParameter("@to", toDate);
                return SqlHelper.ExecuteDataTable(Config.ConnectionConfig.ConnectionString, CommandType.StoredProcedure, "[sp_PT_BC5_TongHopLanDenCuaKhachHang]", param);
            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message);
                return new DataTable();
            }
        }
        public DataTable ReportTongHopDoanhThuDichVuPhuTungNhot(DateTime fromDate, DateTime toDate)
        {
            try
            {
                SqlParameter[] param = new SqlParameter[2];
                param[0] = new SqlParameter("@from", fromDate);
                param[1] = new SqlParameter("@to", toDate);
                return SqlHelper.ExecuteDataTable(Config.ConnectionConfig.ConnectionString, CommandType.StoredProcedure, "[sp_PT_BC8_BaoCaoTongHopDoanhThuDV_PT_Nhot]", param);
            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message);
                return new DataTable();
            }
        }
        public DataTable ReportTongHopDoanhThuDichVuPhuTungNhotChiTiet(DateTime fromDate, DateTime toDate)
        {
            try
            {
                SqlParameter[] param = new SqlParameter[2];
                param[0] = new SqlParameter("@from", fromDate);
                param[1] = new SqlParameter("@to", toDate);
                return SqlHelper.ExecuteDataTable(Config.ConnectionConfig.ConnectionString, CommandType.StoredProcedure, "[sp_PT_BC9_BaoCaoChiTietDoanhSoHangKy]", param);
            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message);
                return new DataTable();
            }
        }
        public DataTable AdvanceSearch(int isFinished, string tenKH, string bienSo, string dienThoai, string tuPhieu, string denPhieu, DateTime tuNgay, DateTime denNgay, int nvSuaChua, int nvTiepNhan, int nvKiemTra, int nvThuNgan, string lstDichVu, string lstGiamGiaDichVu, string lstPhuTung, bool isOil, string lstGiamGiaPhuTung, string lstPhanLoaiXe, decimal tongTienTu, decimal tongTienDen, int phutThucHienTu, int phutThucHienDen, string tenhangmuc, string mahangmuc)
        {
            try
            {
                string sql = "sp_PT_SearchBill";
                SqlParameter[] param = new SqlParameter[24];
                param[0] = new SqlParameter("@isFinished", isFinished);
                param[1] = new SqlParameter("@custName", tenKH);
                param[2] = new SqlParameter("@bienSo", bienSo);
                param[3] = new SqlParameter("@dienThoai", dienThoai);
                param[4] = new SqlParameter("@tuPhieu", tuPhieu);
                param[5] = new SqlParameter("@denPhieu", denPhieu);
                param[6] = new SqlParameter("@fromdate", tuNgay);
                param[7] = new SqlParameter("@todate", denNgay);
                param[8] = new SqlParameter("@suachua", nvSuaChua);
                param[9] = new SqlParameter("@tiepnhan", nvTiepNhan);
                param[10] = new SqlParameter("@kiemtra", nvKiemTra);
                param[11] = new SqlParameter("@thungan", nvThuNgan);
                param[12] = new SqlParameter("@lstDichVu", lstDichVu);
                param[13] = new SqlParameter("@lstGiamGiaDichVu", lstGiamGiaDichVu);
                param[14] = new SqlParameter("@lstPhuTung", lstPhuTung);
                param[15] = new SqlParameter("@isShowOil", isOil);
                param[16] = new SqlParameter("@lstGiamGiaPhuTung", lstGiamGiaPhuTung);
                param[17] = new SqlParameter("@lstPhanLoaiXe", lstPhanLoaiXe);
                param[18] = new SqlParameter("@tongTienTu", tongTienTu);
                param[19] = new SqlParameter("@tongTienDen", tongTienDen);
                param[20] = new SqlParameter("@soPhutThucHienTu", phutThucHienTu);
                param[21] = new SqlParameter("@soPhutThucHienDen", phutThucHienDen);
                param[22] = new SqlParameter("@tenhangmuc", tenhangmuc);
                param[23] = new SqlParameter("@mahangmuc", mahangmuc);

                string connectionString = Config.ConnectionConfig.ConnectionString;
                SqlConnection connection = new SqlConnection(connectionString);
                SqlCommand command = new SqlCommand(sql, connection);
                command.CommandType = CommandType.StoredProcedure;
                command.CommandTimeout = 3600;

                for (int i = 0; i < param.Length; i++)
                    command.Parameters.Add(param[i]);

                DataTable dt = new DataTable();
                connection.Open();
                SqlDataAdapter da = new SqlDataAdapter(command);
                da.Fill(dt);
                da.Dispose();
                command.Parameters.Clear();
                
                connection.Close();
                return dt;
            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message);
                return new DataTable();
            }
        }

        public DataTable Report10(DateTime fromDate, DateTime toDate)
        {
            try
            {
                SqlParameter[] param = new SqlParameter[2];
                param[0] = new SqlParameter("@from", fromDate);
                param[1] = new SqlParameter("@to", toDate);
                return SqlHelper.ExecuteDataTable(Config.ConnectionConfig.ConnectionString, CommandType.StoredProcedure, "sp_PT_BC10", param);
            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message);
                return new DataTable();
            }
        }

        public DataTable Report11(DateTime fromDate, DateTime toDate)
        {
            try
            {
                SqlParameter[] param = new SqlParameter[2];
                param[0] = new SqlParameter("@from", fromDate);
                param[1] = new SqlParameter("@to", toDate);
                return SqlHelper.ExecuteDataTable(Config.ConnectionConfig.ConnectionString, CommandType.StoredProcedure, "sp_PT_BC11", param);
            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message);
                return new DataTable();
            }
        }
        public DataTable Report12(DateTime fromDate, DateTime toDate)
        {
            try
            {
                SqlParameter[] param = new SqlParameter[2];
                param[0] = new SqlParameter("@from", fromDate);
                param[1] = new SqlParameter("@to", toDate);
                return SqlHelper.ExecuteDataTable(Config.ConnectionConfig.ConnectionString, CommandType.StoredProcedure, "sp_PT_BC12", param);
            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message);
                return new DataTable();
            }
        }
        public int Update_ChiTietDoanhSoTheoAgent(out string message)
        {
            message = "";
            try
            {
                string sql = "sp_PT_Update_vw_PT_ChiTietDoanhSoTheoAgent";
                string connectionString = Config.ConnectionConfig.ConnectionString;
                SqlConnection connection = new SqlConnection(connectionString);
                SqlCommand command = new SqlCommand(sql, connection);
                SqlParameter param = new SqlParameter();
                param = new SqlParameter("@message", SqlDbType.NVarChar, 1024);
                param.Value = "aa";
                command.Parameters.Add(param);
                param.Direction = ParameterDirection.Output;
                command.CommandType = CommandType.StoredProcedure;
                command.CommandTimeout = 3600;
                connection.Open();
                int t = command.ExecuteNonQuery();
                message = (string)command.Parameters["@message"].Value;
                connection.Close();
                return t;
                //return SqlHelper.ExecuteNonQuery(Config.ConnectionConfig.ConnectionString, CommandType.Text, sql);
            }
            catch (Exception ex)
            {
                _logger.Debug(ex.Message);
                return 0;
            }
        }
    }

}

